package classifier;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import java.util.ArrayList;

public class ClassifierModel{

	private TextFileReader reader;

	private ArrayList<ActionListener> actionListeners;
	private DecisionTree tree;

	public ClassifierModel()throws IOException {
		this.reader = new TextFileReader();
		this.tree = new DecisionTree(this.reader.getTrainingsSet(), this.reader.getFeatures());
		
		this.actionListeners = new ArrayList<ActionListener>();
		notifyActionListeners();
	}
	
	/**
	 * This method will add actionListeners to it's internal registry to notify
	 * when changes occur.
	 * 
	 * @param ActionListener listener
	 */
	public void addActionListener(ActionListener listener){
		this.actionListeners.add(listener);
	}
	
	/**
	 * This method will notify all the registered ActionListeners of change and
	 * hand them a reference to retrieve the new information.
	 */
	private void notifyActionListeners(){
		for(ActionListener listener : actionListeners){
			listener.actionPerformed(new ActionEvent(this, 0, null) );
		}
	}

	/**
	 * @return the tree
	 */
	public Node getTree() {
		//return tree;
		return this.tree.getRoot();
	}




}
